//
//  LSAlartView.m
//  Estate
//
//  Created by heyong on 2016/12/8.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "LSAlartView.h"

@implementation LSAlartView
- (UIButton *)confirmBtn{
    if(!_confirmBtn){
        _confirmBtn=[[UIButton alloc]init];
    }
    return _confirmBtn;
}

- (UIButton *)closeBtn{
    if(!_closeBtn){
        _closeBtn=[[UIButton alloc]init];
    }
    return _closeBtn;
}

- (UILabel *)titleLab{
    if(!_titleLab){
        _titleLab=[[UILabel alloc]init];
    }
    return _titleLab;
}
- (UILabel *)contentText{
    if(!_contentText){
        _contentText=[[UILabel alloc]init];
    }
    return _contentText;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if(self){
        [self createView];
    }
    return self;
}

- (void)setTitleStr:(NSString *)titleStr{
    _titleStr=titleStr;
    self.titleLab.text=_titleStr;
}

- (void)setMsgStr:(NSAttributedString *)msgStr{
    _msgStr=msgStr;
    self.contentText.attributedText=msgStr;
}

- (void)setContentFont:(UIFont *)font{
    self.contentText.font=font;
}

- (void)createView{
    
    UIView *contentView=[[UIView alloc]initWithFrame:CGRECTS(0, 0, 300, 140)];
    contentView.center=self.center;
    contentView.backgroundColor=[UIColor whiteColor];
    contentView.layer.cornerRadius=10.;
    contentView.layer.borderColor=[UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1.00].CGColor;
    contentView.layer.borderWidth=1.;
    
    //标题
    self.titleLab.frame= CGRectMake(0, 0, DEF_WIDTH(contentView), 40*BIZ);
    self.titleLab.layer.cornerRadius=10.;
    self.titleLab.backgroundColor=[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1.00];
    self.titleLab.textColor=[UIColor colorWithRed:0.51 green:0.51 blue:0.51 alpha:1.00];
    self.titleLab.font=[UIFont systemFontOfSize:15.];
    self.titleLab.text=@"删除照片";
    self.titleLab.textAlignment=1;
    [contentView addSubview:self.titleLab];
    
    //文字显示内容
    self.contentText.frame= CGRectMake(0, 40*BIZ, DEF_WIDTH(contentView),70*BIZ);
    self.contentText.textAlignment=1;
    self.contentText.textColor=[UIColor colorWithRed:0.49 green:0.49 blue:0.49 alpha:1.00];
    [self.contentText setAttributedText:self.msgStr];
    [contentView addSubview:self.contentText];
    
    //设置lab上面的圆角
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.contentText.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.contentText.bounds;
    maskLayer.path = maskPath.CGPath;
    self.contentText.layer.mask  = maskLayer;
    
    //分割线
    UIView *lineView=[[UIView alloc]initWithFrame:CGRectMake(0, 100*BIZ,  DEF_WIDTH(contentView), 1)];
    lineView.backgroundColor=[UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.00];
    [contentView addSubview:lineView];
    
    UIView *rowView=[[UIView alloc]init];
    rowView.backgroundColor=[UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.00];
    [contentView addSubview:rowView];
    [rowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(DEF_WIDTH(contentView)/2-0.5);
        make.width.offset(1);
        make.top.mas_equalTo(lineView.mas_bottom).offset(0);
        make.bottom.mas_equalTo(contentView.mas_bottom).offset(0);
    }];
    
    
    //确认btn
   self. confirmBtn= [[UIButton alloc]init];
    [ self. confirmBtn setTitle:@"确认" forState:UIControlStateNormal];
     self. confirmBtn.titleLabel.font=[UIFont systemFontOfSize:16];
    [ self. confirmBtn setTitleColor:[UIColor colorWithRed:0.50 green:0.50 blue:0.50 alpha:1.00] forState:UIControlStateNormal];
    
    [contentView addSubview: self. confirmBtn];
    
    WEAKSELF
    [ self. confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.top.mas_equalTo(lineView.mas_bottom).offset(0);
        make.bottom.mas_equalTo(weakSelf.confirmBtn.mas_bottom).offset(0);
        make.width.offset(DEF_WIDTH(contentView)/2);
    }];
    
    //取消btn
    self.closeBtn=[[UIButton alloc]init];
     self.closeBtn.titleLabel.font=[UIFont systemFontOfSize:16];
    [ self.closeBtn setTitle:@"取消" forState:UIControlStateNormal];
    [ self.closeBtn setTitleColor:[UIColor colorWithRed:0.50 green:0.50 blue:0.50 alpha:1.00] forState:UIControlStateNormal];
    [contentView addSubview: self.closeBtn];
    [ self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(rowView.mas_right).offset(10);
        make.top.mas_equalTo(lineView.mas_bottom).offset(0);
        make.bottom.mas_equalTo(weakSelf.confirmBtn.mas_bottom).offset(0);
        make.width.offset(DEF_WIDTH(contentView)/2);
    }];
    
    [self addSubview:contentView];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
